﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Engine;
using Game.Server.Event;
using Game.Server.PlayerEvent;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using System;
using Game.NetWork.Packages;
using Game.NetWork;
using System.Text;
using System.Security.Cryptography;
using LiteNetLib;

namespace Game.Server.Plugins
{
    public class UPARW_EA : AbstractProcessCmd, IUpdateable, IDrawable// 继承AbstractProcessCmd类， 实现IUpdateable接口
    {
        public UpdateOrder UpdateOrder => UpdateOrder.Default; // 

        public override string Cmd => "say";

        public override string Introduce => "/say  -控制系统说话"; // 指令说明

        public override int AuthLevel => 100; // 指令权限等级

        protected ComponentPlayer componentPlayer; // 玩家组件

        protected SubsystemGameInfo subsystemGameInfo;// 游戏信息组件

        protected SubsystemPlayers subsystemPlayers; // 玩家管理组件

        public override DisplayType Display => DisplayType.NoDisplay; // 指令是否可查看

        public int[] DrawOrders => new int[1001]; // 绘制顺序

        public override void ProcessCmd() // 处理指令
        {
            var method = new 方法集合();
            //object obj = this.m_client.PlayerData.ComponentPlayer;
            subsystemGameInfo = GameManager.Project.FindSubsystem<SubsystemGameInfo>();// 获取游戏信息组件
            componentPlayer = this.m_client.PlayerData.ComponentPlayer;// 获取玩家组件
            subsystemPlayers = GameManager.Project.FindSubsystem<SubsystemPlayers>();// 获取玩家管理组件

            if (GameManager.Project == null) // 判断是否为null
            {
                SendMessage(Cmd, "请先进入存档");
                return;
            }
            if (m_messageDatas.Length != 2) // 判断是否有参数
            {
                SendMessage(Cmd, "/say [系统说的话]");
                return;
            }
            else
            {
                string text = m_messageDatas[1]; // 获取参数
                foreach (PlayerData playersDatum in subsystemPlayers.PlayersData)//遍历玩家
                {
                    componentPlayer = playersDatum.Client.PlayerData.ComponentPlayer;// 获取玩家组件
                    method.SendMsgPack(componentPlayer, text);// 发送消息
                }

            }



        }


        public void Update(float dt) // 实现IUpdateable接口的Update方法 dt为时间间隔
        {

        }

        public void Draw(Camera camera, int drawOrder) // 实现IDrawable接口的Draw方法 camera为相机对象 drawOrder为绘制顺序
        {

        }
    }

    public class SayPlugin : ServerPlugin
    {
        public override int Version => 10000; // 版本号
        public override string Name => "控制系统说话插件"; // 插件名
        public byte FirstLevel => 0; // 优先级

        public override void Initialize()
        {

        }

        public override void Load()
        {
            // 加载存档逻辑
        }

        public override void Save()
        {
            // 保存存档逻辑
        }
    }
    public class 方法集合
    {
        public void DisplayLargeMessageNet(ComponentPlayer componentPlayer, string text, string more, float duration = 2, float delay = 0) // 标题信息方法
        {
            var messagePackget = new MessagePackage(text, more, duration, delay);
            messagePackget.To = componentPlayer.PlayerData.Client;
            CommonLib.Net.QueuePackage(messagePackget);
        }
        public void SendMsgPack(ComponentPlayer componentPlayer, string text)  //发送消息方法
        {
            MessagePackage messagePackage = new MessagePackage(null, text, 0, null);
            messagePackage.To = componentPlayer.PlayerData.Client;
            CommonLib.Net.QueuePackage(messagePackage);
        }

    }
}
